import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

public class Factorizator {
	private int counter = 0;

	private int[] primes;

	public Factorizator(int[] primes) {
		this.primes = primes;
	}

	public int[] factorize(int number) {
		counter++;

		List<Integer> fact = new ArrayList<>();

		int primeIndex = 0;
		while (number > 1) {
			if (number > 1 && number % primes[primeIndex] == 0) {
				number /= primes[primeIndex];
				fact.add(primes[primeIndex]);
			} else {
				primeIndex++;
			}
		}

		return DKUtil.makeIntArray(fact);
	}

	public SortedMap<Integer, int[]> factorizeAllLEQThan(int maxNumber) {
		counter++;

		SortedMap<Integer, int[]> factMap = new TreeMap<Integer, int[]>();

		for (int number = 2; number <= maxNumber; number++) {
			factMap.put(number, factorize(number));
		}

		return factMap;
	}

	public void doLongJob(int maxNumber) {
		factorizeAllLEQThan(maxNumber);
	}

	public int getCount() {
		return counter;
	}
}
